<?php
class App_Page_Model_PageObject extends Main_Db_Table_Abstract
{
	/**
	 * @var string
	 */
	protected $_name = 'page_object';
	
	/**
	 * @var string
	 */
	protected $_primary = 'page_id';
	
	/**
	 * @var array
	 */	
	protected $_fields = array(
		'page_id',
		'name',
		'layout_id',
		'f_map',
		'f_active',
		'agg_url'
	);
	
	/**
	 * 
	 * @var App_Page_Model_Page
	 */
	protected $_modelPage;
	
	/**
	 * (non-PHPdoc)
	 * @see library/Main/Db/Table/Main_Db_Table_Abstract#init()
	 */
	public function init() 
	{
		$this->_modelPage = Main_Model::factory('Page_Model_Page');
	}
	
	/**
	 * @param array $data
	 * @return bool
	 */
	public function insertItem($data) 
	{
		$dataOk = $this->beforeSave($data, array(
			'page_id', 'name', 'layout_id', 'f_map', 'f_active' 
		), array('name'));
		
		$res = $this->insert($dataOk);
		
		return $res;
	}

	/**
	 * @param array $data
	 * @param int $id
	 * @param bool $wasParentChanged
	 * @return bool
	 */
	public function updateItem($data, $id, $wasParentChanged) 
	{
		$dataOk = $this->beforeSave($data, array(
			'name', 'layout_id', 'f_map', 'f_active'
		), array('name'));
    	
    	$res = $this->update($dataOk, "page_id={$id}");
    	
    	return $res;
	}

	/**
	 * @param int $pageId
	 * @return bool
	 */
	public function deleteItemByPageId($pageId) 
	{
		return $this->delete("page_id={$pageId}");
	}
	
}
